#include "config.h"
#include "GPIO_InIt.h"
#include "IR_Exit.h"

unsigned char Address = 0xFF;
unsigned char Command;

u8 NPN;

void UART_config(void)
{
	COMx_InitDefine		COMx_InitStructure;					
	COMx_InitStructure.UART_Mode      = UART_8bit_BRTx;
	COMx_InitStructure.UART_BRT_Use   = BRT_Timer1;
	COMx_InitStructure.UART_BaudRate  = 9600;
	COMx_InitStructure.UART_RxEnable  = ENABLE;
	COMx_InitStructure.BaudRateDouble = DISABLE;
	COMx_InitStructure.UART_Interrupt = ENABLE;
	COMx_InitStructure.UART_Priority  = Priority_0;
	COMx_InitStructure.UART_P_SW      = UART1_SW_P30_P31;
	UART_Configuration(UART1, &COMx_InitStructure);
	EA=1;//中断总开关
}

void main()
{
	GPIO_Init();
	UART_config();
	Timer2_Init();
	IR_Init();
	
	MA=0;
	MB=0;
	while(1)
	{		
		if(IR_GetDataFlag())	//如果收到数据帧或者收到连发帧
		{
			Address=IR_GetAddress();	//获取遥控器地址码
			Command=IR_GetCommand();	//获取遥控器命令码
			TX1_write2buff(Command);
			if(Command==0x0C)
			{
				Yin_Dao=1;
				Delay_ms(1);
				Yin_Dao=0;
			}
			if(Command==0x08)
			{
				JDQ_SW = ~JDQ_SW;
			}	
		}	
		if(IR_GetRepeatFlag())
		{	
			if(Command==0x18)
			{
				MA = 1;
				MB = 0;
			}
			if(Command==0x5E)
			{
				MA = 0;
				MB = 1;
			}	
		}				
	}
}

void Timer2_ISR (void) interrupt 12
{
	if(IR_GetDataFlag()==0 && IR_GetRepeatFlag()==0)
	{
		MA = 0;
		MB = 0;		
	}
}


	
